#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//简化的学生结构
struct student {
    int num;
    char name[10];
    int computer, english, math;
    double average;
};

//出生年月日结构体
struct birthInfo {
    int year;
    int month;
    int day;
};

//地址结构体
struct address {
    char city[100];
    char district[100];
    char street[100];
    int code;
    int zip;
};

//带有出生年月和地址的详细结构体
struct student_w_b_a {
    int num;
    char name[50];
    int computer, english, math;
    double average;
    struct birthInfo birth;
    struct address addr;
};

void soutStruct() {
    int a = sizeof(struct student);
    printf("%d\n", a);
}

//输入n个学生成绩信息，并且根据学生的平均成绩从高到低来进行排序
void sortStudenAverage() {
    int n;
    printf("请输入要记录成绩的学生个数：\n");
    scanf("%d", &n);
    //定义学生结构数组
    struct student stus[50];
    if (n < 0 || n > 50) {
        printf("invalid values:\n");
        return;
    }
    for (int i = 0; i < n; ++i) {
        printf("please enter the info of No.%d \n", i + 1);
        printf("num:");
        scanf("%d", &stus[i].num);
        printf("name:");
        scanf("%s", stus[i].name);
        printf("math score:");
        scanf("%d", &stus[i].math);
        printf("english score:");
        scanf("%d", &stus[i].english);
        printf("computer score:");
        scanf("%d", &stus[i].computer);
        stus[i].average = (stus[i].math + stus[i].english + stus[i].computer) / 3.0;
    }

    //结构数组排序.这里使用的是选择排序 即每次从无序列表中查找最大的或最小的跟无序数组中第一个数组进行交换
    for (int i = 0; i < n - 1; i++) {
        //总共执行n-次即可成功排序
        int k = i;
        for (int j = i + 1; j < n; j++) {
            //从当前无序序列中找出最大值，内循环一次结束后便产生一个无序中的最大值
            if (stus[j].average > stus[k].average) {
                k = j; //最大值所在的下标索引
            }
        } //当前最大值跟外层交换形成有序序列
        struct student temp = stus[k];
        stus[k] = stus[i];
        stus[i] = temp;
    }

    //输出有序序列
    for (int i = 0; i < n; ++i) {
        printf("No.:%d,num:%d,name:%s,math:%d,english:%d,computer:%d,average:%.2f\n", i + 1, stus[i].num, stus[i].name,
               stus[i].math, stus[i].english, stus[i].computer, stus[i].average);
    }
}

//初始化学生数组
struct student *init_student(struct student stus[], int len) {
    for (int i = 0; i < len; ++i) {
        printf("please enter No.%d student info:\n", i + 1);
        printf("num:");
        scanf("%d", &stus[i].num);
        printf("name:");
        scanf("%s", stus[i].name);
        printf("math score:");
        scanf("%d", &stus[i].math);
        printf("english score:");
        scanf("%d", &stus[i].english);
        printf("computer score:");
        scanf("%d", &stus[i].computer);
        stus[i].average = (stus[i].math + stus[i].english + stus[i].computer) / 3.0;
    }
    return stus;
}

//初始化学生数组，是使用结构体数组进行初始化，不用复制数据直接传递地址
struct student *init_student_by_pointer(struct student *p, int len) {
    for (int i = 0; i < len; ++i, p++) {
        printf("please enter No.%d student info:\n", i + 1);
        printf("num:");
        scanf("%d", &p->num);
        printf("name:");
        scanf("%s", p->name);
        printf("math score:");
        scanf("%d", &p->math);
        printf("english score:");
        scanf("%d", &p->english);
        printf("computer score:");
        scanf("%d", &p->computer);
        p->average = (p->math + p->english + p->computer) / 3.0;
    }
    return p;
}

void testPointerInit() {
    struct student stus[10];
    init_student(stus, 3);
    for (int i = 0; i < 3; ++i) {
        printf("No.:%d,num:%d,name:%s,math:%d,english:%d,computer:%d,average:%.2f\n", i + 1, stus[i].num, stus[i].name,
               stus[i].math, stus[i].english, stus[i].computer, stus[i].average);
    }
}

int alterStuScore(struct student stus[], int len, int score, int course, int num) {
    struct student *p;
    p = stus;
    int i, pos;
    //很具学号进行查找
    for (i = 0; i < len; i++, p++) {
        if (p->num == num) {
            break;
        }
    }

    //说明找到学生了
    if (i < len) {
        switch (course) {
            case 1:
                p->math = score;
                break;
            case 2:
                p->english = score;
                break;
            case 3:
                p->computer = score;
                break;
        }
        pos = i;
    } else {
        pos = -1;
    }
    return pos;
}

void testAlterStuScore() {
    struct student stus[3];
    int n = 3;
    init_student(stus, n);
    // for (int i = 0; i < n; ++i) {
    //     printf("No.:%d,num:%d,name:%s,math:%d,english:%d,computer:%d,average:%.2f\n", i + 1, stus[i].num, stus[i].name,
    //            stus[i].math, stus[i].english, stus[i].computer, stus[i].average);
    // }
    //
    printf("please enter students num:\n");
    int num;
    scanf("%d", &num);
    printf("please enter the course to alter:\n");
    int course;
    scanf("%d", &course);
    printf("please enter the score to alter:\n");
    int score;
    scanf("%d", &score);

    int pos = alterStuScore(stus, n, score, course, num);
    if (pos == -1) {
        printf("not found the student info:\n");
    } else {
        printf("after alter:\n");
        printf("num:%d,name:%s,math:%d,english:%d,computer:%d,average:%.2f\n", stus[pos].num, stus[pos].name,
               stus[pos].math, stus[pos].english, stus[pos].computer, stus[pos].average);
    }
}

void test() {
    // printf("%d",3/2);
    // struct example {
    //     struct {
    //         int x, y;
    //     } in;
    //
    //     int a, b;
    // }e;
    // e.a = 1;e.b = 2;
    // e.in.x = e.a*e.b;
    // e.in.y = e.a+e.b;
    // printf("%d,%d",e.in.x,e.in.y);

    struct table {
        int x, y;
    } a[4] = {{10, 20}, {30, 40}, {50, 60}, {70, 80}};
    struct table *p = a;
    printf("%d\n", p++->x);
    printf("%d\n", ++p->y);
    printf("%d\n", (a + 3)->x);
}

struct time {
    int hour;
    int minute;
    int second;
};

void transferTime() {
    struct time t, *p = &t;
    printf("请输入时间格式为h:m:s\n");
    scanf("%d:%d:%d", &p->hour, &p->minute, &p->second);


    int n;
    printf("请输入您要增加的秒数:\n");
    scanf("%d", &n);
    if (n > 60 || n < 0) {
        printf("invilid value ");
        return;
    }
    int i = 0;
    if (p->second + n > 60) {
        i = p->second + n - 60;
    }
    p->second = p->second + n;
    if (p->second + n > 60) {
        p->minute++;
        p->second = i;
        if (p->minute == 60) {
            p->hour++;
            p->minute = 0;
            if (p->hour == 24) {
                p->hour = 0;
            }
        };
    }
}

void seq_init(int a[], int len);

void seq_bubble_sort(int a[], int len);

void seq_quick_sort(int a[], int len);

void seq_print(int a[], int len);

void seq_insert(int a[], int *len, int value);

void seq_delete(int a[], int *len, int value);

void seq_query(int a[], int *len, int value);

# define  MAXN 100

void seq_menu() {
    printf("please enter the seq len:\n");
    int len;
    scanf("%d", &len);
    int a[MAXN];
    seq_init(a, len);
    while (1) {
        printf("======seq table menu======\n");
        printf("[1] Insert\n");
        printf("[2] Delete\n");
        printf("[3] Query\n");
        printf("[Other option] End \n");
        printf("==========================\n");
        printf("enter your option num:\n");
        int o;
        scanf("%d", &o);
        if (o > 3 || o < 0) {
            break;
        }
        printf("please enter the option value:\n");
        int value;
        scanf("%d", &value);

        switch (o) {
            case 1:
                seq_insert(a, &len, value);
                break;
            case 2:
                seq_delete(a, &len, value);
                break;
            case 3:
                seq_query(a, &len, value);
                break;
            default:
                return;
        }
    }
}

void seq_init(int a[], int len) {
    printf("enter seq init method:\n");
    for (int i = 0; i < len; ++i) {
        printf("enter No.%d num:\n", i + 1);
        scanf("%d", &a[i]);
    }
    seq_print(a, len);
    seq_bubble_sort(a, len);
}

void seq_bubble_sort(int a[], int len) {
    // printf("enter seq bubble sort method:\n");
    for (int i = 1; i < len; i++) {
        for (int j = 0; j < len - i; j++) {
            if (a[j] > a[j + 1]) {
                int temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }
    seq_print(a, len);
}

void seq_quick_sort(int a[], int len) {
    // printf("enter seq quick sort method:\n");
    for (int i = 0; i < len - 1; i++) {
        int k = i;
        for (int j = k; j < len; j++) {
            if (a[j] < a[k]) {
                k = j;
            }
        }
        int temp = a[i];
        a[i] = a[k];
        a[k] = temp;
    }
    seq_print(a, len);
}


void seq_print(int a[], int len) {
    printf("enter seq_print method:\n");
    for (int i = 0; i < len; ++i) {
        printf("%3d", a[i]);
    }
    printf("\n");
}

//根据数值插入数据
void seq_insert(int a[], int *len, int value) {
    // printf("enter seq insert method:\n");
    //查询该数值在数组中的索引
    int i;
    for (i = 0; i < *len; ++i) {
        if (a[i] > value) {
            break;
        }
    }
    for (int j = (*len) - 1; j >= i; j--) {
        a[j + 1] = a[j];
    }
    a[i] = value;
    (*len)++;
    seq_print(a, *len);
}

void seq_delete(int a[], int *len, int value) {
    // printf("enter seq delete method:\n");
    //在有序表中查询value下标
    int index = -1;
    for (int i = 0; i < *len; ++i) {
        if (a[i] == value) {
            index = i;
            break;
        }
    }
    if (index == -1) {
        printf("%d not found in seq\n");
        return;
    } else {
        for (int j = index; j < (*len) - 1; j++) {
            a[j] = a[j + 1];
        }
        (*len)--;
        seq_print(a, *len);
    }
}

//二分查找法
void seq_query(int a[], int *len, int value) {
    // printf("enter seq query method:\n");
    int left = 0, right = (*len) - 1, mid;
    while (left <= right) {
        mid = (left + right) / 2;
        if (a[mid] == value) {
            break;
        } else if (value > a[mid]) {
            left = mid + 1;
        } else if (value < a[mid]) {
            right = mid - 1;
        }
    }
    if (left <= right) {
        printf("%d is in seq index is %d\n", value, mid);
    } else {
        printf("%d is not found\n", value);
    }
}

double fact(int n);

//递归求阶乘
double fact(int n) {
    double result;
    if (n == 1 || n == 0) {
        result = 1;
    } else {
        result = n * fact(n - 1);
    }
    return result;
}

//辗转相除求最大公因数
int gcd(int m, int n) {
    if (m % n == 0) {
        return n;
    } else {
        return gcd(m, m % n);
    }
}

//递归求数组中最大值
int max_by_fact(int a[], int m, int n) {
    int k, u, v;
    if (m == n) {
        return a[m];
    } else {
        k = (m + n) / 2;
        u = max_by_fact(a, m, k);
        v = max_by_fact(a, k + 1, n);
        return u > v ? u : v;
    }
}

int min_by_fact(int a[], int m, int n) {
    int k, u, v;
    if (m == n) {
        return a[m];
    } else {
        k = (m + n) / 2;
        u = min_by_fact(a, m, k);
        v = min_by_fact(a, k + 1, n);
        return u < v ? u : v;
    }
}

int sum_by_fact(int n) {
    if (n == 1) {
        return 1;
    } else {
        return n + sum_by_fact(n - 1);
    }
}

//宏定义一般直接就是字符串拼接
#define max(x,y) (x*y)
#define F(x) x-2
#define D(x) x*F(x)
// int x = 5,y = 7;
void swap() {
    // int z;
    // z = x;x=y;y=z;
    printf("%d,%d",D(3),D(D(3)));
}

int f(int n, int a) {
    if (n == 0) return a;
    return f(n - 1, n * a);
}

void str_sort() {
    char *pcolor[] = {"red", "bule", "yellow", "green", "black"};

    char **p = pcolor;
    char *temp;
    for (int i = 1; i < 5; ++i) {
        for (int j = 0; j < 5 - i; ++j) {
            if (strcmp(*(p + j), *(p + j + 1)) > 0) {
                temp = *(p + j);
                *(p + j) = *(p + j + 1);
                *(p + j + 1) = temp;
            }
        }
    }

    for (int i = 0; i < 5; i++) {
        printf("%s  ", *p++);
    }
}

char *match(char *p, char ch) {
    char *q;
    while (*p != '\0') {
        if (*p == ch) {
            // q = p;
            // printf("%c",*p);
            return p;
        }
        p++;
    }
    return NULL;
}

void test_match() {
    char *p = "program";
    char ch = 'y';
    if ((p = match(p, ch)) != NULL) {
        while (*p != '\0') {
            printf("%c", *p++);
        }
    } else {
        printf("NOT FOUND!");
    }
}

double calc(double (*funp)(double), double a, double b) {
    double z;
    z = (b - a) / 2 * ((*funp)(a) + (*funp)(b));
    return (z);
}

double f1(double x) {
    return x * x;
}

double f2(int x);

double f2(int x) {
    return (sin(x) / x);
}

void test_funp() {
    double result;
    double (*fun_1)(double) = f2;
    result = calc(fun_1, 1.0, 2.0);
    printf("%.4f\n", result);
}

/**
 * 判断素数
 * @param m 参数
 * @return 0不是是素数1是素数
 */
int prime(int m);

int prime(int m) {
    if (m <= 1) {
        return 0;
    } else if (m == 2) {
        return 1;
    } else {
        for (int i = 2; i < (sqrt(m) + 1); i++) {
            if (m % i == 0) {
                return 0;
            }
        }
        return 1;
    }
}

void write_prime_file() {
    //写2开始500个素数到文件中
    int n = 2, count = 0;
    FILE *fp;
    if ((fp = fopen("prime.txt", "w")) == NULL) {
        printf("FILE OPEN ERROR!\n");
        exit(0);
    }
    while (count < 500) {
        if (prime(n) != 0) {
            count++;
            fprintf(fp, "No.%d:%d\n", count, n);
            // fprintf(fp, "%d", n);
        }
        n++;
    }
    if (fclose(fp)) {
        printf("FILE CLOSE ERROR!");
        exit(0);
    }
}

struct sysuser {
    char name[50];
    char pwd[50];
};

//加密算法低四位取反，高四位不变
void encrypt(char *pwd) {
    for (int i = 0; i < strlen(pwd); i++) {
        pwd[i] = pwd[i] ^ 15;
    }
}

void write_encrypt_user_info() {
    struct sysuser su;
    FILE *fp;
    if ((fp = fopen("f12-2.txt", "w")) == NULL) {
        printf("open file error!:\n");
        exit(0);
    }
    for (int i = 0; i < 5; ++i) {
        printf("please enter No.%d username passwrod:\n", i + 1);
        scanf("%s%s", su.name, su.pwd);
        encrypt(su.pwd);
        fprintf(fp, "%s %s\n", su.name, su.pwd);
    }
    if (fclose(fp)) {
        printf("file close error!\n");
        exit(0);
    }
}

//备份文件
void copy_file() {
    FILE *fpr;
    FILE *fpw;
    char name[100];
    if ((fpr = fopen("f12-2.txt", "r")) == NULL) {
        printf("read file error!\n");
        exit(0);
    }
    if ((fpw = fopen("f12-3.txt", "w")) == NULL) {
        printf("open file error!\n");
        exit(0);
    }
    //读文件和写文件
    fgets(name, 100, fpr);
    fputs(name, fpw);
    if (fclose(fpw)) {
        printf("close file error:\n");
        exit(0);
    }
    if (fclose(fpr)) {
        printf("close file error:\n");
        exit(0);
    }
}

int check_pwd() {
    char username[30], password[30], account[30];
    FILE *fp;
    printf("please enter your username password:\n");
    scanf("%s%s", username, password);

    // 对用户输入的密码进行加密
    encrypt(password);
    // 拼接用户输入的账号和加密后的密码
    strcat(username, " ");
    strcat(username, password);
    strcat(username, "\n");
    // 打开文件
    if ((fp = fopen("f12-2.txt", "r")) == NULL) {
        printf("open file error:\n");
        exit(0);
    }
    // 读文件
    while (fgets(account, 1024, fp) != NULL) {
        if (strcmp(username, account) == 0) {
            // printf("find account:\n");
            return 1;
        }
    }
    // 关闭文件
    if (fclose(fp)) {
        printf("close file error:\n");
        exit(0);
    }
    return 0;
    //
}

//读写二进制文件
void write_and_read_binary_file() {
    FILE *fw;
    struct sysuser su[5], *pu;
    for (int i = 0; i < 5; i++) {
        printf("please enter No.%d user username password:\n", i + 1);
        scanf("%s%s", su[i].name, su[i].pwd);
        encrypt(su[i].pwd);
    }
    pu = su;
    //打开文件
    if ((fw = fopen("f12-5.dat", "wb+")) == NULL) {
        printf("open file error:\n");
        exit(0);
    }
    //写入文件
    fwrite(pu, sizeof(struct sysuser), 5, fw);
    rewind(fw); //文件指针从新回到文件首部
    fread(pu, sizeof(struct sysuser), 5, fw);
    for (int i = 0; i < 5; ++i, pu++) {
        printf("-10%s%s\n", pu->name, pu->pwd);
    }

    if (fclose(fw)) {
        printf("close file error:\n");
        exit(0);
    }
}

void file_trans_small_case() {
    FILE *fp;
    char ch;
    int count = 0;
    if ((fp = fopen("f12-4.txt", "r")) == NULL) {
        printf("open file error:\n");
        exit(0);
    }
    while (!feof(fp)) {
        ch = fgetc(fp);
        if (ch != EOF) {
            if (ch >= 'A' && ch <= 'Z') {
                ch = ch - 'A' + 'a';
            } else if (ch == '\n') {
                count++;
            }
            // fputc(ch, fp);
            printf("%c", ch);
        }
    }
    printf("\ncount=%d:\n", count);
    // 关闭文件
    if (fclose(fp)) {
        printf("close file error:\n");
        exit(0);
    }
}

//对文件中的整数读取
void tranfer_num() {
    FILE *fpw, *fpr;
    int i;
    float f;
    if ((fpr = fopen("f1.txt", "r")) == NULL) {
        printf("read file error:\n");
        exit(0);
    }
    if ((fpw = fopen("f2.txt", "w")) == NULL) {
        printf("read file error:\n");
        exit(0);
    }
    while (!feof(fpr)) {
        fscanf(fpr, "%d%lf", &i, &f);
        f = round(f);
        fprintf(fpw, "%d %d", i, f);
    }
    if (fclose(fpw)) {
        printf("close file error:\n");
        exit(0);
    }
    if (fclose(fpr)) {
        printf("close file error:\n");
        exit(0);
    }
}

#include<process.h>

struct LogData {
    long logId;
    char logDate[11]; //日期
    char logNote[50]; //流水说明
    double charge; //本次费用
    double balance; //余额
};

int size;

void addCashLog(FILE *fp);

void listAllCashLog(FILE *fp);

void queryLastLog(FILE *fp);

int getLogCount(FILE *fp);

void closeFilePointer(FILE *fp);

void logDataMenu() {
    int chioce;
    FILE *fp;
    // struct logData su;
    size = sizeof(struct LogData);
    if ((fp = fopen("cashbox.dat", "r+")) == NULL) {
        printf("open file error:\n");
        exit(0);
    }
    do {
        scanf("%d", &chioce);
        printf("========logdata system========\n");
        printf("1.add new cash log\n");
        printf("2.list all cash log\n");
        printf("3.query last cash log\n");
        printf("0.exit\n");
        printf("enter your chioce:\n");
        switch (chioce) {
            case 1:
                addCashLog(fp);
                break;
            case 2:
                listAllCashLog(fp);
                break;
            case 3:
                queryLastLog(fp);
            default:
                break;
        }
    } while (chioce != 0);
    closeFilePointer(fp);
}

void addCashLog(FILE *fp) {
    struct LogData log, lastlog;
    long logcount;
    printf("input logdate (format:xxxx-xx-xx):\n");
    scanf("%s", log.logDate);
    printf("input lognote:\n");
    scanf("%s", log.logNote);
    printf("input logcharge:\n");
    scanf("%lf", &log.charge);
    //获取文件中当前记录的数量
    logcount = getLogCount(fp);

    if (logcount > 0) {
        //找到最后一个记录
        fseek(fp, size * (logcount - 1),SEEK_SET);
        fread(&lastlog, size, 1, fp);
        log.logId = lastlog.logId + 1;
        log.balance = lastlog.balance + log.charge;
    } else {
        log.logId = 1;
        log.balance = log.charge;
    }
    rewind(fp);
    printf("new log.id=%ld\n", log.logId);
    fwrite(&log, size, 1, fp);
}

void listAllCashLog(FILE *fp) {
    struct LogData log;
    rewind(fp);
    fread(&log, size, 1, fp);
    printf("\n");
    printf("logId      logDate          logNote          charge  balance:\n");
    while (!feof(fp)) {
        printf("%6ld %-11s %-15s %10.2lf %10.2lf\n", log.logId, log.logDate, log.logNote, log.charge, log.balance);
        fread(&log, size, 1, fp);
    }
    printf("\n");
}

void queryLastLog(FILE *fp) {
    struct LogData log;
    int logcount = getLogCount(fp);
    if (logcount > 0) {
        fseek(fp, -size,SEEK_END);
        fread(&log, size, 1, fp);
        printf("\n");
        printf("logId       logDate             logNote         charge  balance:\n");

        printf("%6ld %-11s %-15s %10.2lf %10.2lf\n", log.logId, log.logDate, log.logNote, log.charge, log.balance);
        printf("\n");
    } else {
        printf("no logs in file:\n");
    }
}

int getLogCount(FILE *fp) {
    struct LogData log;
    int logcount = 0;
    rewind(fp);
    fread(&log, size, 1, fp);
    while (!feof(fp)) {
        logcount++;
        fread(&log, size, 1, fp);
    }
    return logcount;
}

void closeFilePointer(FILE *fp) {
    if (fclose(fp)) {
        printf("close file error:\n");
        exit(0);
    }
}

void updateLog(FILE *fp, long logId) {
    struct LogData log, lastLog;
    int count = 0;
    double charge = 0;
    long position = 0;
    fread(&log, size, 1, fp);
    while (!feof(fp)) {
        if (log.logId == logId) {
            position = ftell(fp);
            break;
        }
        fread(&log, size, 1, fp);
        count++;
    }
    //存在的情况
    if (count <= getLogCount(fp)) {
        printf("please enter update charge:\n");
        scanf("%lf", &charge);
        rewind(fp);
        fseek(fp, position,SEEK_SET);
        log.balance = log.balance - log.charge + charge;
        log.charge = charge;
        fwrite(&log, size, 1, fp);
        fseek(fp, position + size,SEEK_SET);
        fread(&lastLog, size, 1, fp);
        while (!feof(fp)) {
            lastLog.balance = lastLog.balance - log.charge + charge;
            fwrite(&lastLog, size, 1, fp);
            fread(&lastLog, size, 1, fp);
        }
    } else {
        printf("not found:\n");
    }
}

void testfy() {
    char ch;
    while ((ch = getchar()) != '#') {
        putchar(ch);
        ch = getchar();
    }
}


//直接插入排序，从第二个元素开始进行n-1次循环，找到比当前元素的元素，然后将他们全部都向后移，找到当前元素位置将元素放到当前位置
#define MAXSIZE 10
#define FALSE 0
#define TRUE 1

typedef struct {
    int data[MAXSIZE];
    int legth;
} Sqlist;

void initSqlist(Sqlist *L) {
    L->legth = 0;
}

int insertSqlist(Sqlist *L, int n) {
    if (n > MAXSIZE - 1 || n <= 0) {
        return FALSE;
    }
    int i = 1;
    while (i <= n) {
        printf("please enter %d.num:\n", i);
        scanf("%d", &L->data[i]);
        i++;
    }
    L->legth += n;
    return TRUE;
}

void sqlistPrint(Sqlist *L) {
    // printf("%d\n", L->legth);
    int i = 0;
    while (i < L->legth + 1) {
        printf("%4d", L->data[i]);
        i++;
    }
    printf("\n");
}


void insertSort(Sqlist *L) {
    int j;
    for (int i = 2; i <= L->legth; i++) {
        if (L->data[i] < L->data[i - 1]) {
            L->data[0] = L->data[i];
            for (j = i - 1; L->data[j] > L->data[0]; j--) {
                L->data[j + 1] = L->data[j];
            }
            L->data[j + 1] = L->data[0];
        }
    }
}

void testSqlist() {
    Sqlist L;
    initSqlist(&L);
    insertSqlist(&L, 9);
    sqlistPrint(&L);
    insertSort(&L);
    sqlistPrint(&L);
}

int main(void) {
    testSqlist();
    // testfy();
    // tranfer_num();
    // printf("res:=%d", check_pwd());
    // write_encrypt_user_info();
    // write_prime_file();
    // test_funp();
    // test_match();
    // str_sort();
    // swap();
    // printf("%d",f(6,1));
    // testGetMax();
    // printf("%d", gcd(3, 1));
    // seq_menu();
    // test();
    // testPointerInit();
    // testAlterStuScore();
    // sortStudenAverage();
    // soutStruct();
}
